package com.cy.personer.biz.impl;

import com.cy.personer.bean.Combo;
import com.cy.personer.biz.ComboBiz;
import com.cy.personer.ceptor.OperationLog;
import com.cy.personer.mapper.ComboMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 套餐服务层实现类
 * @author 林少艺
 */
@Service
public class ComboBizImpl implements ComboBiz {

    @Resource
    ComboMapper comboMapper;

    /**
     * 查询套餐列表
     * @param combo
     * @param pageNum
     * @return
     * @author 林少艺
     */

    @Override
    public PageInfo<Combo> getCombos(Combo combo,int pageNum) {
        Page<Combo> page = PageHelper.startPage(pageNum,5);
        comboMapper.getCombos(combo);
        PageInfo<Combo> comboPageInfo = new PageInfo<>(page);
        return comboPageInfo;
    }

    /**
     * 查询套餐详情
     * @param combo
     * @return
     * @author 林少艺
     */
    @Override
    public Combo getCombo(Combo combo) {
        return comboMapper.getCombo(combo);
    }

    /**
     * 假删除套餐
     * @param combo
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="删除",methods = "删除套餐" )
    @Override
    public boolean delCombo(Combo combo) {
        combo.setStateId(6);
        return comboMapper.delCombo(combo)>0;
    }

    /**
     * 增加套餐
     * @param combo
     * @return
     * @author 林少艺
     */
    @OperationLog(operType="添加",methods = "新增套餐" )
    @Override
    public boolean addCombo(Combo combo) {
        combo.setComboId(comboMapper.getNewComboId());
        comboMapper.addCombo(combo);
        return comboMapper.addComboItem(combo)==combo.getItems().size();
    }
}
